#ifndef KEYEDLIST_H_
#define KEYEDLIST_H_

#include <string.h>

#include "List.h"
#include "KeyedEntry.h"

#include <stdio.h>
template <class T>
class KeyedList
{
	List< KeyedEntry<T> > * entries;
	
	public:
	KeyedList();
	KeyedList(char * key, T * value);
	~KeyedList();
	T * GetValue(char * key);
	void Add(char * key, T * value);
};
template<class T>
KeyedList<T>::KeyedList()
{
	entries = NULL;	
}

template<class T>
KeyedList<T>::KeyedList(char * key, T * value)
{
	entries = new List< KeyedEntry<T> >(new KeyedEntry<T>(key, value), NULL);	
}
template<class T>
KeyedList<T>::~KeyedList()
{
	if(entries)
	{
		delete(entries);
		entries = NULL;
	}
}
template<class T>
T * KeyedList<T>::GetValue(char * key)
{
	List< KeyedEntry<T> > * search = entries;
	while(search)
	{
		if(search->payload && strcmp(search->payload->GetKey(), key) == 0)
		{
			return search->payload->GetValue();
		}
		search = search->next;	
	}
	return NULL;
}
template<class T>
void KeyedList<T>::Add(char * key, T * value)
{
	entries = new List< KeyedEntry<T> >(new KeyedEntry<T>(key, value), entries);
}
#endif /*KEYEDLIST_H_*/
